<template>
	<view class="container">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption" :top="230">
			<view v-for="(item,index) in list" :key="index">
				<curdTempalte :statusCode="statusCode" :itemDetail="item"  @Acceptance="Acceptance"/>
			</view>			
		</mescroll-uni>
	</view>
</template>

<script>
	import curdTempalte from './curdTemplate.vue';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import { findClientReviewInfo, toAcceptThe } from '@/api/clientreview.js'
	export default {
		components:{
			curdTempalte
		},
		mixins: [MescrollMixin],
		props:{
			statusCode:{type:String/Number,default:'1'},
			deliveryTime:{type:String/Number,default:''}
		},
		watch:{
			statusCode(val){
				this.downCallback()
			}
		},
		data(){
			return {
				upOption:{
					auto:false
				},
				pages:0,
				list:[]
			}
		},
		methods:{
			downCallback(){
				this.list = []
				this.mescroll.resetUpScroll( true )				
			},
			async upCallback(page){
				// console.log('-----调用了-------')
				let params = {
					pageIndex:page.num,
					pageSize:page.size,
					statusCode: this.statusCode,
					deliveryTime:this.deliveryTime
				}
				let res = await findClientReviewInfo(params)
				console.log('res',res)
				if(res.result === '1'){
					this.mescroll.endSuccess(res.rows.length)
					this.list = [...this.list,...res.rows]
				} else {
					this.mescroll.endErr()
				}
				
			},
			async Acceptance(e){	
				if(!e.orderCode){
					uni.showToast({
						 title: '该工单异常',
						 icon:'error',
						 duration: 2000
					})
				}
				let res = await toAcceptThe({orderCode:e.orderCode})
				uni.showToast({
					 title: res.msg,
					 icon:'none',
					 duration: 2000
				})
				if(res.result === '1'){
					this.mescroll.triggerDownScroll()
				} 
				console.log(e)
			}
		}
	}
</script>

<style>

</style>
